package com.change.study.data.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.change.study.data.core.Pagination;
import com.change.study.data.core.Updater;
import com.change.study.data.dao.PostsTagDao;
import com.change.study.data.entity.PostsTag;
import com.change.study.data.service.PostsTagService;

@Service
@Transactional
public class PostsTagServiceImpl implements PostsTagService {
	@Transactional(readOnly = true)
	public Pagination getPage(int pageNo, int pageSize) {
		Pagination page = dao.getPage(pageNo, pageSize);
		return page;
	}

	@Transactional(readOnly = true)
	public PostsTag findById(Long id) {
		PostsTag entity = dao.findById(id);
		return entity;
	}

    @Transactional
	public PostsTag save(PostsTag bean) {
		dao.save(bean);
		return bean;
	}

    @Transactional
	public PostsTag update(PostsTag bean) {
		Updater<PostsTag> updater = new Updater<PostsTag>(bean);
		bean = dao.updateByUpdater(updater);
		return bean;
	}

    @Transactional
	public PostsTag deleteById(Long id) {
		PostsTag bean = dao.deleteById(id);
		return bean;
	}

    @Transactional	
	public PostsTag[] deleteByIds(Long[] ids) {
		PostsTag[] beans = new PostsTag[ids.length];
		for (int i = 0,len = ids.length; i < len; i++) {
			beans[i] = deleteById(ids[i]);
		}
		return beans;
	}

	private PostsTagDao dao;

	@Autowired
	public void setDao(PostsTagDao dao) {
		this.dao = dao;
	}
}